﻿using System;
using System.Collections;
using System.Collections.Generic;

using IBatisNet.DataAccess;

using AUV5.Model;
using AUV5.DAL;
using AUV5.DAL.Interface;
using AUV5.DAL.Dao;

namespace AUV5.BLL
{
    /// <summary>
    /// 功能：     OrderItem业务逻辑实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class OrderItemBLL
    {
        private static OrderItemBLL instance = null;
        private static object syncRoot = new object();
        private IDaoManager daoManager = ServiceConfig.Instance.DaoManager;
        private IOrderItemDao dao = null;

        private OrderItemBLL()
        {
            dao = OrderItemSqlMapDao.Instance;
        }

        public static OrderItemBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new OrderItemBLL();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                //daoManager.BeginTransaction();

                int count = dao.GetMaxCounts();

                //daoManager.CommitTransaction();

                return count;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderItem> GetList()
        {
            try
            {
                //daoManager.BeginTransaction();

                System.Collections.Generic.IList<OrderItem> list = dao.GetList();

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private System.Collections.Generic.IList<OrderItem> GetListByParameters(object TopCounts, OrderItem orderitem)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                System.Collections.Generic.IList<OrderItem> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="OrderItemID"></param>
        /// <returns></returns>
        public OrderItem GetDetail(System.String orderitemid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.GetDetail(orderitemid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public object Add(OrderItem orderitem)
        {
            //int id = GetId("SYS_UserInfoTemp");
            //sys_userinfotemp.UserID = id;

            try
            {
                ///daoManager.BeginTransaction();

                return dao.Add(orderitem);
                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public int Update(OrderItem orderitem)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Update(orderitem);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="OrderItemID"></param>
        /// <returns></returns>
        public int Delete(System.String orderitemid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(orderitemid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public int Delete(OrderItem orderitem)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(orderitem);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        #region##通过条件得到订单项个数
        /// <summary>
        /// 通过条件得到订单项个数
        /// 创建人：Wilson
        /// 创建时间：2011-10-12
        /// </summary>
        /// <param name="objParamters"></param>
        /// <returns></returns>
        public int GetOrderItemQuantityCountByCondition(string serviceId,int statusID)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("StatusID",Convert.ToString(statusID));
                ht.Add("ServiceID", serviceId);
                return dao.GetOrderItemQuantityCountByCondition(ht);
            }
            catch
            {

                throw;
            }
        }
        #endregion

        #region## 通过订单ID得到订单项详情
        /// <summary>
        /// 通过订单ID得到订单项详情
        /// 创建人：Wilson
        /// 创建时间：2011-10-30
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public OrderItem GetOrderItemByOrderID(string orderId)
        {
            try
            {
                return dao.GetOrderItemByOrderID(orderId);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        /// <summary>
        /// 通过服务ID查询订单项
        /// </summary>
        /// <param name="serviceID"></param>
        /// <returns></returns>
        public IList<OrderItem> GetOrderItemByServiceID(string serviceID)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("serviceID",serviceID);
                ht.Add("state",(int)Common.Enum.auvState.Enabled);
                ht.Add("isDel", (int)Common.Enum.auvDel.NotDel);

                IList<OrderItem> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        #region## 通过订单ID得到订单附加服务
        /// <summary>
        /// 通过订单ID得到订单附加服务
        /// 创建人：Wilson
        /// 创建时间：2011-12-18
        /// </summary>
        /// <param name="objParamters"></param>
        /// <returns></returns>
        public IList<OrderItem> GetOrderItemExtra(string orderId)
        {
            try
            {              
                Hashtable ht = new Hashtable();
                ht.Add("OrderID", orderId);
                ht.Add("ExtraID","");
                ht.Add("State", (int)Common.Enum.auvState.Enabled);
                ht.Add("IsDel", (int)Common.Enum.auvDel.NotDel);

                IList<OrderItem> list = dao.GetOrderItemExtra(ht);

                return list;
            }
            catch
            {               
                throw;
            }
        }
        #endregion

    }
}
